﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using ProjetLabo.Controls;
using ProjetLabo.Class.Utils.Database;

namespace ProjetLabo.Manager
{
    /// <summary>
    /// Logique d'interaction pour Manager.xaml
    /// </summary>
    public partial class Manager : Window
    {



        private DataBaseNotify bdd;

        public DataBaseNotify Bdd
        {
            get { return bdd; }
            set { bdd = value; }
        }

        public Manager()
        {
            InitializeComponent();
            //Recuperation ou initialize bdd

            this.bdd = new DataBaseNotify();


            Binding bind = new Binding();
            bind.Source = this.bdd.TablesCollection;
            this.ListControolTable.SetBinding(Controls.ControlTable.TableDependency, bind);

        }


        #region ajouttable
        //Nouvelle table
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            #region old
            /*if (listtable.Count > 0)
            {
                    for (int j = 0; j < this.GridTable.RowDefinitions.Count; j++)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            foreach (ControlTable t in listtable)
                            {
                                if (Grid.GetColumn(t) == i && Grid.GetRow(t) == j)//SI un contorl est a cette emplacement
                                {
                                    lastcolumn = i;
                                    lastRow = j;
                                }
                            }
                        }
                }
                if (lastcolumn == 2)
                {
                    Grid.SetColumn(table, 0);
                    Grid.SetRow(table, lastRow + 1);
                }
                else
                {
                    Grid.SetColumn(table, lastcolumn + 1);
                    Grid.SetRow(table, lastRow);
                }   
            }
            else
            {
                Grid.SetRow(table, 0);
                Grid.SetColumn(table, 0);
            }*/
            #endregion

            //ControlTable table = new ControlTable();
            //table.EventCLique += table_EventCLique;
            DataTable table = new DataTable();
            this.Bdd.TablesCollection.Add(table);
            

        }
        #endregion

        void table_EventCLique(object arg1, EventArgs arg2)
        {
            //arg1 correspond au controlTable
            //Ici ajouter un lien (clé étrangère)
        }

        

        //Enregistrement du schema
        private void Save_click(object sender, RoutedEventArgs e)
        {
            //sauvegarder un dataset et lenvoyer a romain

        }




        
    }
}
